package com.example.wanghui.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

class PrimeAdapter(private val primes: List<Int>) : RecyclerView.Adapter<PrimeAdapter.PrimeViewHolder>() {

    class PrimeViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val primeTextView: TextView = view.findViewById(android.R.id.text1)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PrimeViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(android.R.layout.simple_list_item_1, parent, false)
        return PrimeViewHolder(view)
    }

    override fun onBindViewHolder(holder: PrimeViewHolder, position: Int) {
        holder.primeTextView.text = primes[position].toString()
    }

    override fun getItemCount(): Int = primes.size
}